package com.yy.train.ticket.train.controller;

import java.util.List;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.train.ticket.into.BuyTicket;
import com.yy.train.ticket.into.page.OrderPage;
import com.yy.train.ticket.train.entity.TtTicketEntity;
import com.yy.train.ticket.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TuOrderEntity;
import com.yy.train.ticket.train.service.TuOrderService;





/**
 * 订单
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-25 10:38:44
 */
@RestController
@RequestMapping("tu/order")
public class TuOrderController {
    @Autowired
    private TuOrderService tuOrderService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(@RequestParam OrderPage orderPage){

        LambdaQueryWrapper<TuOrderEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        Page<TuOrderEntity> pages = new Page<TuOrderEntity>(orderPage.getPageNum(), orderPage.getPageSize());
        IPage<TuOrderEntity> iPage = tuOrderService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);
    }


    @PostMapping("/buyTicket")
    public R buyTicket(@RequestBody TtTicketEntity ttTicketEntity){
        return  tuOrderService.buyTicket(ttTicketEntity.getTicketId());
    }
    @PostMapping("/buySectionTicket")
    public R buySectionTicket(@RequestBody TtTicketEntity ttTicketEntity){
        return  tuOrderService.buySectionTicket(ttTicketEntity);
    }

    @PostMapping("/shop")
    public R shop(@RequestBody TtTicketEntity ttTicketEntity){
        return  tuOrderService.shop(ttTicketEntity);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{orderId}")
    public R info(@PathVariable("orderId") Long orderId){
		TuOrderEntity tuOrder = tuOrderService.getById(orderId);

        return R.ok(tuOrder);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody TuOrderEntity tuOrder){
		tuOrderService.save(tuOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TuOrderEntity tuOrder){
		tuOrderService.updateById(tuOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody List<Integer> orderIds){
		tuOrderService.removeByIds(orderIds);

        return R.ok();
    }

}
